export const mixin = {
  methods:{
    notify(title,type){
      this.$notify({
        title: title,
        type: type
      })
    },
    //返回性别文字
    changeSex (value) {
      if (value === 0) {
        return '女'
      } else if (value === 1) {
        return '男'
      } else if (value === '男' || value === '女') {
        return value
      }
    },
    changeStyle(value){
      switch(value){
        case 1:return '动画'
        case 2:return '音乐'
        case 3:return '舞蹈'
        case 4:return '知识'
        case 5:return '生活'
        case 6:return '时尚'
        case 7:return '娱乐'
        case 8:return '美食'
        case 9:return '游戏'
        case 10:return '番剧'
        case 11:return '国创'
        case 12:return '数码'
        case 13:return '鬼畜'
        case 14:return '资讯'
        case 15:return '影视'
        case 16:return '搞笑'
        case 17:return '动物'
        case 18:return 'VLOG'
        case 19:return '其他'
      }
    },
    //返回日期
    attachDate (val) {
      let Date = String(val).match(/[0-9-]+(?=\s)/)
      return Array.isArray(Date) ? Date[0] : Date
    },
    //获取地址
    getUrl(url){
      return `${this.$store.state.HOST}/${url}`
    },
    //用户提交头像前校验
    beforeAvatarUpload(file){
      const isJPG = (file.type === 'image/jpeg')||(file.type === 'image/png')
      if(!isJPG){
        this.$message.error('上传头像图片只能是jpg或png格式')
        return false
      }
      const isLt2M = (file.size /1024/1024)<2
      if(!isLt2M){
        this.$message.error('上传的头像图片大小不能超过2MB')
        return false
      }
      return true
    },
    //用户提交头像后
    handleAvatarSuccess(res){
      let _this = this
      if(res.code == 1){
        _this.getData()
        _this.$notify({
          title: '上传成功',
          type: 'success'
        });
      }else{
        _this.$notify({
          title: '上传失败',
          type: 'error'
        });
      }
    },
    //把已经选择的项赋值给multipleSelection
    handleSelectionChange(val){
      this.multipleSelection = val
    },
    //弹出是否删除窗口
    handleDelete(id){
      this.idx = id
      this.delVisible = true
    },
    delAll(){
      for(let item of this.multipleSelection){
        this.handleDelete(item.id)
        this.deleteRow()
      }
      this.multipleSelection = [];
    },
    
    formatTime(value){
      let theTime = parseInt(value)
      let result = ''
      let hour = parseInt(theTime/3600)
      let minute = parseInt(theTime/60%60)
      let second = parseInt(theTime%60)
      if(hour > 0){
        if(hour < 10){
          result = '0' + hour +':'
        }else{
          result = hour + ':'
        }
      }
      if (minute > 0) {
        if(minute < 10){
          result += 0 + minute + ''
        }else{
          result += minute + ':'
        }
      }else{
        result += '00:'
      }
      if (second > 0) {
        if (second < 10) {
          result += '0' +second
        }else{
          result += second
        }
      }else{
        result += '00'
      }
      return result
    }
  }
}